<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *      [PinTuXiu] (C)2001-2099 ONightjar.com Pintuxiu.com.
 *      This is NOT a freeware, use is subject to license terms
 */

class admin_db extends Model{
	
	public function dbversion() {
		$rs = $this->findSql("SELECT VERSION() AS v");
		return array_pop($rs);
	}
	
	public function dbsize() {
		$dbsize = 0;
		$rs = $this->findSql("SHOW TABLE STATUS LIKE '".$this->dbpre."%'", 'SILENT');
		foreach ($rs as $table){
			$dbsize += $table['Data_length'] + $table['Index_length'];
		}
		return $dbsize;
	}
	
	public function gettablestatus($tablename, $formatsize = true) {
		$rs = $this->findSql("SHOW TABLE STATUS LIKE '".str_replace('_', '\_', $tablename)."'");
		$status = array_pop($rs);
		if($formatsize) {
			$status['Data_length'] = sizecount($status['Data_length']);
			$status['Index_length'] = sizecount($status['Index_length']);
		}
		return $status;
	}
}